package com.hex.ds.code.detection.common.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.validation.annotation.Validated;

import java.util.Locale;

/**
 * 脚本扫描结果
 *
 * @author Wang zhihao
 * @date 2023-10-07 17:48:50
 */
@Data
@Validated
@TableName("TD_SCRIPT_PACK_SCAN_RESULT")
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "脚本扫描结果")
@Accessors(chain = true)
public class ScriptPackScanResultEntity extends Model<ScriptPackScanResultEntity> {
private static final long serialVersionUID = 1L;

    /**
     * 扫描结果ID
     */
    @TableId(type= IdType.ASSIGN_UUID)
    @ApiModelProperty(value="扫描结果ID")
    private String id;
    /**
     * 扫描清单ID
     */
    @ApiModelProperty(value="扫描清单ID")
    private String scanListId;
    /**
     * 扫描任务ID
     */
    @ApiModelProperty(value="扫描任务ID")
    private String scanTaskId;
    /**
     * 文件名称
     */
    @ApiModelProperty(value="文件名称")
    private String fileName;
    /**
     * 脚本文件类型(init/period/service)
     */
    @ApiModelProperty(value="脚本文件类型(init/period/service)")
    private String fileType;
    /**
     * 脚本文件类型名称
     */
    @ApiModelProperty(value="脚本文件类型名称")
    @TableField(exist = false)
    private String fileTypeName;
    /**
     * 扫描状态
     */
    @ApiModelProperty(value="扫描状态")
    private String scanState;
    /**
     * 扫描状态名称
     */
    @ApiModelProperty(value="扫描状态名称")
    @TableField(exist = false)
    private String scanStateName;
    /**
     * 扫描等级
     */
    @ApiModelProperty(value="扫描等级")
    @TableField(exist = false)
    private String scanLevel;
    /**
     * 扫描表名
     */
    @ApiModelProperty(value="扫描表名")
    private String scanTable;
    /**
     * sql类型
     */
    @ApiModelProperty(value="sql类型")
    private String sqlType;
    /**
     * 扫描项
     */
    @ApiModelProperty(value="扫描项")
    private String scanItem;
    /**
     * 扫描项描述
     */
    @ApiModelProperty(value="扫描项描述")
    private String scanItemDescribe;
    /**
     * 扫描内容描述
     */
    @ApiModelProperty(value="扫描内容描述")
    private String scanDescInfo;
    /**
     * 扫描代码块
     */
    @ApiModelProperty(value="扫描代码块")
    private String scanSql;
    /**
     * 扫描代码块编号
     */
    @ApiModelProperty(value="扫描代码块编号")
    private String scanSqlIndex;
    /**
     * 是否忽略异常
     */
    @ApiModelProperty(value="是否忽略异常")
    private String ignoreException = "N";

    /**
     * 删除标识
     */
    @ApiModelProperty(value="删除标识")
    @TableField(fill = FieldFill.INSERT)
    private String del;
    public Integer getScanSqlIndexAsInt() {
        return Integer.parseInt(this.scanSqlIndex);
    }

    public String getScanStateName() {
        switch (scanState.toUpperCase(Locale.ROOT)) {
            case "SUCCESS":
                return "扫描成功";
            case "WARNING":
                return "扫描告警";
            case "IGNORE":
                return "扫描告警(已忽略)";
            case "DEFAULT":
                return "代码块未涉及";
            case "FAIL":
                return "扫描异常";
            case "ANTLRFAIL":
                return "代码块解析异常";
            case "BADSQL":
                return "SQL语法异常";
            case "ERROR":
                return "校验出现错误";
            default:
                return "";
        }
    }
}
